<template>
  <!--<a-card :bordered="false">-->
  <a-row :gutter="10">
    <a-col :md="14" :sm="24">
      <a-card :bordered="false">
        <!-- 操作按钮区域 -->
        <div class="table-operator">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap1"
            :scroll="{x:true}"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type:'radio'}"
            :customRow="clickThenSelect"
            @change="handleTableChange">

            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text,record">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width:80px;font-size: 12px;font-style: italic;"/>
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
              <a-button
                v-else
                :ghost="true"
                type="primary"
                icon="download"
                size="small"
                @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <a @click="handleEdit(record)">编辑</a>
              <template v-if="record.systemOwned === 0">
                <a-divider type="vertical" />
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </template>
            </span>
          </a-table>
        </div>
      </a-card>
    </a-col>
    <a-col :md="10" :sm="24">
      <a-card :bordered="false">
        <a-tabs defaultActiveKey="1">
          <a-tab-pane tab="仓库储位信息" key="1" >
            <StorageLocationList
              :mainId="storageLocationMainId"
              :main-code="storageLocationMainCode" />
          </a-tab-pane>
        </a-tabs>
      </a-card>
    </a-col>
    <warehouse-modal ref="modalForm" @ok="modalFormOk"></warehouse-modal>
  </a-row>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import WarehouseModal from './modules/WarehouseModal.vue'
  import { getAction } from '@/api/manage'
  import StorageLocationList from './StorageLocationList.vue'
  import {initDictOptions,filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import '@/assets/less/TableExpand.less'

  export default {
    name: "WarehouseList",
    mixins:[JeecgListMixin],
    components: {
      StorageLocationList,
      WarehouseModal
    },
    data () {
      return {
        description: '仓库信息管理页面',
        // 表头
        columns: [
          {
            title:'仓库编码',
            align:"center",
            dataIndex: 'warehouseCode'
          },
          {
            title:'仓库名称',
            align:"center",
            dataIndex: 'warehouseName'
          },
          {
            title:'仓库类型',
            align:"center",
            dataIndex: 'warehouseType_dictText',
          },
          {
            title:'所属部门',
            align:"center",
            dataIndex: 'sysOrgCode_dictText',
          },
          {
            title:'入库通知单',
            align:"center",
            dataIndex: 'inboundNotice_dictText',
          },
          {
            title:'出库通知单',
            align:"center",
            dataIndex: 'outboundNotice_dictText',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/wms/basic/warehouse/list",
          delete: "/wms/basic/warehouse/delete",
          deleteBatch: "/wms/basic/warehouse/deleteBatch",
          exportXlsUrl: "/wms/basic/warehouse/exportXls",
          importExcelUrl: "/wms/basic/warehouse/importExcel",
        },
        dictOptions:{
         warehouseType:[],
         sysOrgCode:[],
         inboundNotice:[],
         outboundNotice:[],
        },
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 20,
          pageSizeOptions: ['5', '10', '20', '50'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        selectedMainId:'',
        superFieldList:[],
        storageLocationMainId: '',
        storageLocationMainCode: '',
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
        initDictOptions('yes_no').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'inboundNotice', res.result)
          }
        })
        initDictOptions('yes_no').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'outboundNotice', res.result)
          }
        })
      },
      clickThenSelect(record) {
        return {
          on: {
            click: () => {
              this.onSelectChange(record.id.split(","), [record]);
            }
          }
        }
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.selectedMainId=''
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedMainId=selectedRowKeys[0]
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
        this.storageLocationMainId = selectionRows[0]['id']
        this.storageLocationMainCode = selectionRows[0]['warehouseCode']
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        this.onClearSelected()
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'warehouseCode',text:'仓库编码',dictCode:''})
        fieldList.push({type:'string',value:'warehouseName',text:'仓库名称',dictCode:''})
        fieldList.push({type:'string',value:'warehouseType',text:'仓库类型',dictCode:'warehouse_type'})
        fieldList.push({type:'list_multi',value:'sysOrgCode',text:'所属部门',dictTable:"sys_depart", dictText:'depart_name', dictCode:'org_code'})
        fieldList.push({type:'int',value:'inboundNotice',text:'入库通知单',dictCode:'yes_no'})
        fieldList.push({type:'int',value:'outboundNotice',text:'出库通知单',dictCode:'yes_no'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>